<?php
require_once '../sub/init.php';
$id=intval($id);
if (!ifint($id)){
	if($js==1){
		json_exit(array('flag'=>0,'msg'=>'亲，群不存在~'));
	}else{
		zeaialert('{"title":"亲，群不存在~","btnt":"我知道了","url":"-1"}');
	}
}
require_once ZEAI.'sub/conn.php';
require_once ZEAI.'cache/udata.php';
$jumpurl = mHref('qun',$id);
$urole = json_decode($_ZEAI['urole'],true);sort($urole);
/*读库*/
$row = $db->ROW(__TBL_QUN__,"*","flag>0 AND id=".$id,"name");
if ($row){
	$id           = $row['id'];
	$title        = dataIO($row['title'],'out');
	$title2       = dataIO($row['title2'],'out');
	$content      = dataIO($row['content'],'out');
	$uid = intval($row['uid']);
	$path_s    = $row['path_s'];
	$bn_s      = $row['bn_s'];
	$areaid    = dataIO($row['areaid'],'out');
	$areatitle = dataIO($row['areatitle'],'out');
	$joinnum = dataIO($row['joinnum'],'out');
	$price   = dataIO($row['price'],'out');
	$tag     = dataIO($row['tag'],'out');
	$flag    = intval($row['flag']);
	$click   = intval($row['click']);
	$addtime = $row['addtime'];
	$chatqx   = dataIO($row['chatqx'],'out');
	$addloveb = abs(intval($row['addloveb']));
	$addhhnum = abs(intval($row['addhhnum']));
	$addqxnum = abs(intval($row['addqxnum']));
	$tj = json_decode(dataIO($row['tj'],'out'),true);
	if(!empty($path_s)){
		$path_s_url = UP.$path_s;
	}else{
		$path_s_url = RES.'noP.gif';
	}
	if(!empty($bn_s)){
		$bn_b_url = UP.smb($bn_s,'b');
	}else{
		$bn_b_url = RES.'m/img/qun_bnr.jpg';
	}
	$area_s_title  = explode(' ',$areatitle);
	$area_s_title1 = $area_s_title[1];
	$area_s_title2 = $area_s_title[2];
	$area_s_title  = $area_s_title1.$area_s_title2;
	$share_title = $title.' - '.$area_s_title.'交友相亲群'.' - '.$_ZEAI['siteName'];
	$share_desc  = trimhtml($content);
	$joinnumARR = json_decode($joinnum,true);
	$priceARR = json_decode($price,true);
	//
	$tj_sex=$tj['sex'];
	$tj_age=$tj['age'];$tj_ageARR=explode(',',$tj_age);$tj_age1=intval($tj_ageARR[0]);$tj_age2=intval($tj_ageARR[1]);
	$tj_love=$tj['love'];
	$tj_edu=$tj['edu'];
	$tj_pay=$tj['pay'];
	$tj_house=$tj['house'];
	$tj_car=$tj['car'];
	$tj_areaid = $tj['areaid'];
	$tj_areatitle = $tj['areatitle'];
	$tj_area2id = $tj['area2id'];
	$tj_area2title = $tj['area2title'];
	$tj_grade = (empty($tj['grade']))?array():explode(',',$tj['grade']);
	$tj_before = (empty($tj['before']))?array():explode(',',$tj['before']);
	$tj_before_bfb_num = intval($tj['before_bfb_num']);
}else{
	zeaialert('{"title":"当前群不存在","btnt":"我知道了","url":"-1"}');
}
//我的信息
$cook_uid=intval($cook_uid);
$iflogin=iflogin();$ifed=false;
if($iflogin){
	$row = $db->ROW(__TBL_USER__,"money,sex,grade,birthday,love,edu,pay,house,car,areaid,area2id,RZ,myinfobfb,photo_s,photo_f","id=".$cook_uid,'name');
	$cook_money = $row['money'];
	$cook_sex   = $row['sex'];
	$cook_grade = $row['grade'];
	$cook_birthday = $row['birthday'];
	$cook_love = $row['love'];
	$cook_edu  = $row['edu'];
	$cook_pay  = $row['pay'];
	$cook_house= $row['house'];
	$cook_car  = $row['car'];
	$cook_areaid = $row['areaid'];
	$cook_area2id= $row['area2id'];
	$cook_RZ = $row['RZ'];$cook_RZarr=explode(',',$cook_RZ);
	$cook_myinfobfb = $row['myinfobfb'];
	$cook_photo_s   = $row['photo_s'];
	$cook_photo_f   = $row['photo_f'];
	$mybmprice  = $priceARR[$cook_sex.'_'.$cook_grade];
	$joinnum    = intval($joinnumARR[$cook_sex]);
	if ($db->ROW(__TBL_QUN_U__,"id","qid=".$id." AND uid=".$cook_uid))$ifed=true;
}
if($submitok=='joinqun'){
	if (!$iflogin)json_exit(array('flag'=>'nologin','jumpurl'=>$jumpurl));
	if ($ifed)json_exit(array('flag'=>0,'msg'=>'您已经加入过了，请不要重复申请'));
	$curnum = $db->COUNT(__TBL_QUN_U__,"qid=".$id);
	if($curnum>=$joinnum && $joinnum>0)json_exit(array('flag'=>0,'msg'=>'<center class=\"B S18\">群员已满</center><br>当前'.udata('sex',$cook_sex).'性群员已满 <font class=Cf00>'.$joinnum.'</font> 人（超出人数限定），暂时不能加入哦'));
	if($flag==2)json_exit(array('flag'=>0,'msg'=>'<center class=\"B S18\">关闭加入</center><br>由于种种原因，本群暂时关闭新成员加入'));
	if(!empty($tj_sex) && !in_array($cook_sex,explode(',',$tj_sex)))json_exit(array('flag'=>0,'msg'=>'您的【性别】不符合入群条件哦'));
	if(!empty($tj_age)){
		$cook_age=intval(getage($cook_birthday));
		if($cook_age<$tj_age1 && $tj_age1>0 || $cook_age>$tj_age2 && $tj_age2>0 )json_exit(array('flag'=>0,'msg'=>'您的【年龄】不符合入群条件哦'));
	}
	if(!empty($tj_love) && !in_array($cook_love,explode(',',$tj_love)))json_exit(array('flag'=>0,'msg'=>'您的【婚况】不符合入群条件哦'));
	if(!empty($tj_edu) && !in_array($cook_edu,explode(',',$tj_edu)))json_exit(array('flag'=>0,'msg'=>'您的【学历】不符合入群条件哦'));
	if(!empty($tj_pay) && !in_array($cook_pay,explode(',',$tj_pay)))json_exit(array('flag'=>0,'msg'=>'您的【月薪】不符合入群条件哦'));
	if(!empty($tj_house) && !in_array($cook_house,explode(',',$tj_house)))json_exit(array('flag'=>0,'msg'=>'您的【房子】不符合入群条件哦'));
	if(!empty($tj_car) && !in_array($cook_car,explode(',',$tj_car)))json_exit(array('flag'=>0,'msg'=>'您的【车子】不符合入群条件哦'));
	if(!empty($tj_areaid)){
		if( empty($cook_areaid) || !empty($cook_areaid) && !strstr($cook_areaid,getareaSQL($tj_areaid)) )json_exit(array('flag'=>0,'msg'=>'您的【工作地区】不符合入群条件哦'));
	}
	if(!empty($tj_area2id)){
		if( empty($cook_area2id) || !empty($cook_area2id) && !strstr($cook_area2id,getareaSQL($tj_area2id)) )json_exit(array('flag'=>0,'msg'=>'您的【户籍地区】不符合入群条件哦'));
	}
	//if(!empty($tj_grade) && !in_array($cook_grade,$tj_grade))json_exit(array('flag'=>0,'msg'=>'您的【会员等级】不符合入群条件哦'));
	//前置条件
	$json=array("ARR"=>$tj_before,"jumpurl"=>$jumpurl,"RZarr"=>$cook_RZarr,"cook_sex"=>$cook_sex,"cook_grade"=>$cook_grade,"cook_photo_f"=>$cook_photo_f,"cook_myinfobfb"=>$cook_myinfobfb,"data_bfb_num"=>$tj_before_bfb_num,"js"=>$js);
	Before_TJ(encode_json($json));
	if(!empty($tj_grade) && !in_array($cook_grade,$tj_grade)){
		$json_str=str_replace('"','\"',uicon($cook_sex.$cook_grade)).utitle($cook_grade).' <i class=\"ico C999\">&#xe62c;</i> <font class=\"Cf00\">我</font><br><br>';
		foreach ($tj_grade as $g){
			$my_json_str=($g==$cook_grade)?'':' <i class=\"ico C090\">&#xe60f;</i>　';
			$json_str.=str_replace('"','\"',uicon($cook_sex.$g)).utitle($g).$my_json_str.'<br><br>';
		}
		json_exit(array('flag'=>'nolevel','msg'=>'您的【会员等级】不符合入群条件哦<br>只差一步，升级对应VIP后即可加入<br><br>'.$json_str,'jumpurl'=>$jumpurl));
	}
	if($flag==1 && $mybmprice>0){	
		json_exit(array('flag'=>'startpay','msg'=>'支付','money'=>$mybmprice));
	}else{
		$db->query("INSERT INTO ".__TBL_QUN_U__."  (qid,uid,addtime) VALUES ($id,$cook_uid,".ADDTIME.")");
		$SQL = "";
		if($addloveb>0)$SQL .= ",loveb=loveb+$addloveb";
		if($addhhnum>0)$SQL .= ",hh_num=hh_num+$addhhnum";
		if($addqxnum>0)$SQL .= ",crm_qxnum=crm_qxnum+$addqxnum";
		if($addloveb>0 || $addhhnum>0 || $addqxnum>0)$db->query("UPDATE ".__TBL_USER__." SET endtime=".ADDTIME.$SQL." WHERE id=".$cook_uid);
		if($addloveb>0)$db->AddLovebRmbList($cook_uid,'加入单身群',$addloveb,'loveb',15);	
		json_exit(array('flag'=>1,'msg'=>'<center class=\"C090 S18 B\"><i class=\"ico\">&#xe67f;</i> 加入成功</center><br>恭喜您成为本群中的一员，您可以与群友一起交流邂逅~~~<br><br>'));
	}
}
$db->query("UPDATE ".__TBL_QUN__." SET click=click+1 WHERE id=".$id);
$TRnav_btn='hide';
$switch = json_decode($_ZEAI['switch'],true);
?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $share_title.$_ZEAI['siteName'];?></title>
<?php echo HEADMETA; ?>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/u.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/qun.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/qun.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php if (is_weixin()){
	require_once ZEAI."api/weixin/jssdk.php";
	?>
	<script src="<?php echo RES;?>jweixin-1.2.0.js"></script>
	<script>wx.config({debug:false,appId: '<?php echo $signPackage["appId"];?>',timestamp: <?php echo $signPackage["timestamp"];?>,nonceStr: '<?php echo $signPackage["nonceStr"];?>',signature: '<?php echo $signPackage["signature"];?>',jsApiList:['hideMenuItems','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo']});
	var share_title = '<?php echo $share_title; ?>',share_desc='<?php echo $share_desc; ?>',share_link='<?php echo $jumpurl; ?>',share_imgurl='<?php echo $path_s_url; ?>';
	wx.ready(function () {
		wx.onMenuShareAppMessage({title:share_title,desc:share_desc,link:share_link,imgUrl:share_imgurl});
		wx.onMenuShareTimeline({title:share_title,desc:share_desc,link:share_link,imgUrl:share_imgurl});
	});
    </script>
<?php }?>
<style>
body{background-color:#f5f5f5}
.dtl_btm a{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>;box-shadow:0 3px 8px rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.4)}
.dtl_box .fuliul li{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.05);border:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.1) 1px solid}
</style>
</head><body>
<a class="UgobackFix" href="qun.php"><i class='ico'>&#xe602;</i></a>
<div class="Ublack" id="TRnav_btn"><i class="ico">&#xe614;</i></div>
<div class="dtl_bnr">
    <div class="bg"><img src="<?php echo $bn_b_url; ?>" /><dl><dt><img src="<?php echo $path_s_url; ?>" /></dt><dd><h2><?php echo $title;?></h2><h5><?php echo $title2;?></h5></dd></dl></div>
    <div class="clear"></div>
</div>
<div class="dtl_box dtl_C"><b>群介绍</b><em><?php echo $content;?></em></div>
<div class="dtl_box" onClick="zeai.openurl('qun_ulist.php?qid=<?php echo $id;?>')">
	<b>群成员<?php
	$rtt = $db->query("SELECT COUNT(*) FROM ".__TBL_QUN_U__." a,".__TBL_USER__." U WHERE a.uid=U.id AND (U.flag=1 OR U.flag=-2) AND a.qid=$id");
	$roww = $db->fetch_array($rtt);
	$total = $roww[0];
	if($total>0)echo '<font class="zeaicolor">（'.$total.'人）</font>';?></b>
	<?php
	if(ifint($uid)){
		$SQL = " AND a.uid<>$uid ";
		$lmt = 4;
	}else{
		$lmt = 5;
	}
    $rt=$db->query("SELECT U.nickname,U.sex,U.photo_s,U.photo_f,U.photo_ifshow,U.flag AS uflag,a.uid FROM ".__TBL_QUN_U__." a,".__TBL_USER__." U WHERE a.uid=U.id AND (U.flag=1 OR U.flag=-2) AND a.qid=$id".$SQL." ORDER BY a.id DESC LIMIT $lmt");
    $total = $db->num_rows($rt);
    if ($total > 0 || ifint($uid)) {
        echo '<ul class="uli">';
		$qzstr='';$uecho='';
        for($i=1;$i<=$total;$i++) {
            $rows = $db->fetch_array($rt,'name');
            if(!$rows) break;
			$uecho .= qun_u_row($rows);
        }
		if(ifint($uid)){
			$row = $db->ROW(__TBL_USER__," nickname,sex,photo_s,photo_f,photo_ifshow,flag AS uflag","id=".$uid,"name");
			if ($row)echo qun_u_row($row,true);
		}
        echo $uecho.'<i class="ico">&#xe601;</i></ul>';
    }else{echo "<div class='nodatatips'>暂无成员</div>";}?>
	<div class="clear"></div>
</div>
<div class="dtl_box">
	<b>加入条件</b>
    <ul class="tjul">
	<?php 
	$tjstr = '';
	if(!empty($tj_sex)){$tjstr .= '<li><font class="C999">性别：</font>'.str_replace(",","，",udata('sex',$tj_sex)).'</li>';}
	if(ifint($tj_age1) || ifint($tj_age2)){$tjstr .= '<li><font class="C999">年龄：</font>'.mateset_out($tj_age1,$tj_age2,'岁').'</li>';}
	if(!empty($tj_love)){$tjstr .= '<li><font class="C999">婚况：</font>'.str_replace(",","，",udata('love',$tj_love)).'</li>';}
	if(!empty($tj_edu)){$tjstr .= '<li><font class="C999">学历：</font>'.str_replace(",","，",udata('edu',$tj_edu)).'</li>';}
	if(!empty($tj_pay)){$tjstr .= '<li><font class="C999">月薪：</font>'.str_replace(",","，",udata('pay',$tj_pay)).'</li>';}
	if(!empty($tj_house)){$tjstr .= '<li><font class="C999">房子：</font>'.str_replace(",","，",udata('house',$tj_house)).'</li>';}
	if(!empty($tj_car)){$tjstr .= '<li><font class="C999">车子：</font>'.str_replace(",","，",udata('car',$tj_car)).'</li>';}
	if(!empty(trimm($tj_areatitle))){$tjstr .= '<li><font class="C999">地区：</font>'.$tj_areatitle.'</li>';}
	if(!empty(trimm($tj_area2title))){$tjstr .= '<li><font class="C999">户籍：</font>'.$tj_area2title.'</li>';}
	if(count($tj_grade)>0){
		foreach($urole as $RV){
			$gstr .= (in_array($RV['g'],$tj_grade))?'【'.$RV['t'].'】':'';
		}
		$tjstr .= '<li><font class="C999">会员等级：</font>'.$gstr.'</li>';
	}
	if (count($tj_before) > 0 ){
		foreach ($tj_before as $V){
			$bfbstr=($V == 'bfb')?$tj_before_bfb_num.'%':'';
			$qtstr .= (in_array($V,$tj_before))?'【'.chatContact_data_title($V).$bfbstr.'】':'';
		}
		$tjstr .= '<li><font class="C999">其它条件：</font>'.$qtstr.'</li>';
	}
	echo $tjstr;?>
    </ul>
</div>
<div class="dtl_box">
	<b>入群福利</b>
	<ul class="fuliul">
    	<?php if ($addloveb>0 || $addhhnum>0 || $addqxnum>0){?>
        <li>
        <?php if ($addloveb>0){?><div>赠送<?php echo $_ZEAI['loveB'];?><b><?php echo $addloveb ;?></b>个<?php if(in_array('chat',$navarr)){?>，<?php echo $_ZEAI['loveB'];?>可与群友解锁畅聊<?php }?><?php if(in_array('contact',$navarr)){?>，<?php echo $_ZEAI['loveB'];?>可以直接查看群友联系方式<?php }?></div><?php }?>
        <?php if(in_array('contact_hh',$navarr) && $addhhnum>0){?><div>赠送与群友互换微信手机<b><?php echo $addhhnum ;?></b>次</div><?php }?>
        <?php if(in_array('hn',$navarr) && $addqxnum>0){?><div>赠送红娘人工牵线<b><?php echo $addqxnum ;?></b>次，享有与优质线下资源邂逅的机会</div><?php }?>
        </li>
        <?php }?>
        ● 群内集中了精准条件优质会员，入群后能更精准快速找到意中人。<br><br>
        ● 入群会员都是急需脱单会员，非常期待与群友偶遇相识。<br><br>
        ● 入群会员有机会拥有与高端人士相识并发展成爱情。<br><br>
    </ul>
</div>
<div class="dtl_btm">
<?php
$ifpaybox=false;
if ($ifed){
	echo '<a class="enter fadeInUp" href="qun_trend.php?qid='.$id.'"><i class="ico">&#xe64d;</i> 立即进群</a>';
}else{
	if($flag==2){
		echo '<a style="background-color:#ccc">暂时关闭新成员加入</a>';
	}else{
		if($iflogin){
			$pricelist_str = '<div class="pricelist">';
			foreach ($urole as $uv) {
				if($uv['f']==0)continue;
				$num   = $priceARR[$cook_sex.'_'.$uv['g']];
				$num_str = ($num>0)?' <font class="Cf00">￥'.$num.'</font> ':'　<font class="C090">免费</font>　<a class="btn size1 VIP" href="my_vip.php?jumpurl='.$jumpurl.'">立通升级</a>';
				$ifmy = ($cook_grade==$uv['g'])?'　<font class=Cf00>（我）</font>':'';
				$pricelist_str .= '<em>'.uicon($cook_sex.$uv['g']).' '.$uv['t'].' <i class="ico">&#xe62d;</i>'.$num_str.$ifmy.'</em>';
			}
			$pricelist_str .= '</div>';
			if($mybmprice>0){
				$price_str = '<i class="ico">&#xe8d5;</i> 立即加入 ￥'.$mybmprice;
				$ifpaybox=true;
			}else{
				$price_str = '<i class="ico">&#xe8d5;</i> 免费加入';
			}
			echo '<a onclick="joinqunFn();" class="zeaibg fadeInUp">'.$price_str.'</a>';
		}else{
			rsort($priceARR);$maxprice=max($priceARR);
			sort($priceARR);$minprice=min($priceARR);
			$price_str = ($maxprice>0)?'<i class="ico">&#xe8d5;</i> 立即加入 ￥'.$minprice.'-'.$maxprice:'<i class="ico">&#xe8d5;</i> 免费加入';
			echo '<a class="zeaibg fadeInUp"  href="'.mHref('login').'?jumpurl='.$jumpurl.'"  >'.$price_str.'</a>';
		}
	}
}?>
</div>
<?php
if($ifpaybox){
	$jump_url = $jumpurl;
	$money = $mybmprice;
	$kind  = 21;
	echo '<input type="hidden" id="money" value="'.$money.'">';
	require_once 'my_pay.php';
}?>
<div id="backtop"><a href="#top" id="btmTopBtn"><i class="ico zeaicolor">&#xe60c;</i><font class="zeaicolor">顶部</font></a></div>
<?php require_once ZEAI.'m/TRnav.php';?>
<script>
var pH=<?php echo (is_weixin())?30.5:37.5;?>,
browser='<?php echo browser();?>',mybmprice=<?php echo $mybmprice;?>,pricelist_str='<?php echo $pricelist_str;?>',id=<?php echo $id;?>;
document.body.onscroll = backtop_alone;
</script>
<div class="blank"></div></body></html>
<?php
function qun_u_row($rows,$ifqz=false) {
	global $uid,$switch,$cook_grade;
	$uflag    = $rows['uflag'];
	$sex      = $rows['sex'];
	$photo_s  = $rows['photo_s'];
	$photo_f  = $rows['photo_f'];
	$photo_ifshow = $rows['photo_ifshow'];
	$unickname= trimhtml(dataIO($rows['nickname'],'out'));
	$photo_s_url=photo_s_out('{"smb":"s","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"url"}');
	$tzstr = ($ifqz)?'<font class="zeaibg">群主</font>':'';
	$uecho = '<li><img src="'.$photo_s_url.'"><span>'.$unickname.'</span>'.$tzstr.'</li>';
	return $uecho;
}
function chatContact_data_title($var) {
	switch ($var){
		case 'rz_mob':$t = '完成手机认证';break;
		case 'rz_identity':$t = '完成实名认证';break;
		case 'rz_photo':$t = '完成真人认证';break;
		case 'bfb':$t = '资料完整度达';break;
		case 'photo':$t = '有头像且已审';break;
		case 'vip':$t = 'VIP用户';break;
	}
	return $t;
}
?>